Skip to content

Set up Vitest Testing Infrastructure and Core Utilities Tests (vertex app)#3692

Merged
Baalmart merged 6 commits into
stagingfrom
unit-testing-setup
Jun 28, 2026
Merged

Set up Vitest Testing Infrastructure and Core Utilities Tests (vertex app)#3692
Baalmart merged 6 commits into
stagingfrom
unit-testing-setup

Conversation

@Codebmk

@Codebmk Codebmk commented Jun 28, 2026

Copy link
Copy Markdown
Member

Description

This PR establishes the foundational automated testing infrastructure for the Vertex project using Vitest and React Testing Library. It fulfills Phase 1 and partially Phase 2 of our testing implementation plan.

Additionally, it introduces unit tests for several highly stable core utilities, establishes internal testing documentation for future contributors, and integrates automated test runs directly into our GitHub Actions CI pipeline to prevent regressions.

What was changed

🛠️ Infrastructure & Tooling

  • Vitest Setup: Installed and configured vitest, jsdom, and @testing-library/* tailored for the Next.js App Router environment (vitest.config.ts, vitest.setup.ts).
  • NPM Scripts: Added npm run test, npm run test:watch, and npm run test:coverage to package.json.
  • CI/CD Integration: Updated .github/workflows/safe-checks.yml to automatically run Type Check (npx tsc --noEmit) and Test & Coverage (npm run test:coverage) on Pull Requests.

🧪 Unit Tests Added

Added comprehensive unit tests for the following core utilities:

  • clientCache.ts
  • cohortName.ts
  • getApiErrorMessage.ts
  • rememberedAccounts.ts
  • sessionManager.ts
  • status.ts
  • urlHelpers.ts
  • userPreferences.ts

📚 Documentation & Cleanup

  • Created internal testing guidelines at src/vertex/app/_docs/internal/TESTING.md.
  • Updated README.md to reference the new testing scripts.
  • Cleanup: Deleted src/vertex/core/utils/responsive.ts (deprecated/unused).

Type of change

  • New feature (non-breaking change which adds functionality)
  • Internal Infrastructure / Tooling
  • Documentation Update

How Has This Been Tested?

  • Ran npm run test:coverage locally and verified all tests pass.
  • Verified vitest correctly uses the jsdom environment and alias mappings (@/).
  • Triggered the .github/workflows/safe-checks.yml locally/remotely to ensure the pipeline correctly executes the Type Check and Test steps.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • I have added/updated the relevant documentation

What are the relevant tickets?

Summary by CodeRabbit

  • New Features
    • Added Vitest-based test scripts for running tests, watching, and generating coverage.
    • Improved automated test environment with React Testing Library + jsdom support and consistent in-memory storage.
  • Documentation
    • Added Vertex testing documentation and expanded guidance on test writing and conventions.
  • Tests
    • Added/expanded unit tests for utilities including status handling, URL helpers, user preferences, remembered accounts, session cleanup, API error messaging, cohort naming, and client cache maintenance.
  • Chores / Refactor
    • Updated CI to include TypeScript type-checking and test+coverage, and moved Vertex Node setup to a newer version.
    • Removed responsive breakpoint helper exports (isDesktop, isMobile, isTablet).

Codebmk added 4 commits June 28, 2026 12:17
Add Vitest-based testing to the vertex package: introduces vitest.config.ts and vitest.setup.ts and updates package.json and tsconfig to support tests. Adds dev dependencies for vitest, @testing-library/react, @testing-library/jest-dom, @testing-library/user-event, jsdom and @vitejs/plugin-react to enable running React component tests in a jsdom environment.
Add comprehensive unit tests for core utility modules (clientCache, cohortName, getApiErrorMessage, rememberedAccounts, sessionManager, status, urlHelpers, userPreferences). Remove obsolete responsive.ts. Update Vitest config to set jsdom URL and enhance vitest.setup.ts to polyfill/localize localStorage and sessionStorage in the test environment to ensure consistent behavior across tests.
Add a comprehensive testing guide and expose test npm scripts. Updated src/vertex/README.md to list `npm run test`, `npm run test:watch`, and `npm run test:coverage` and added src/vertex/app/_docs/internal/TESTING.md which documents Vitest/React Testing Library usage, file organization, mocking guidance, coverage expectations, and a PR checklist to standardize how tests are written and run across the Vertex project.
Run TypeScript type checking and test coverage in the safe-checks CI job by adding a `tsc --noEmit` step and a `npm run test:coverage` step under src/vertex. Configure Vitest coverage to use the V8 provider and emit text, JSON, and HTML reports; coverage thresholds are present but intentionally commented out for now.
@Codebmk Codebmk self-assigned this Jun 28, 2026
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a509c68d-6a5d-41d4-a023-b3ec3cf9d3c6

📥 Commits

Reviewing files that changed from the base of the PR and between 8baa34d and 55b2e8a.

📒 Files selected for processing (2)
  • .github/workflows/safe-checks.yml
  • src/vertex/core/utils/clientCache.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/vertex/core/utils/clientCache.test.ts

📝 Walkthrough

Walkthrough

Adds Vitest/RTL testing infrastructure for src/vertex, expands CI verification with type-check and coverage, adds testing docs, and introduces new utility test suites for storage-backed and pure helper modules.

Changes

Vertex Testing Infrastructure and Utility Tests

Layer / File(s) Summary
Vitest config, setup, deps, and tsconfig wiring
src/vertex/vitest.config.ts, src/vertex/vitest.setup.ts, src/vertex/package.json, src/vertex/tsconfig.json
Creates Vitest config and setup files, adds test scripts and test dependencies, and extends TypeScript types for Vitest and jest-dom.
CI checks and testing documentation
.github/workflows/safe-checks.yml, src/vertex/README.md, src/vertex/app/_docs/internal/TESTING.md
Updates the Vertex workflow with type-check and coverage steps, adds a testing section to the README, and adds the internal testing guide.
Storage-backed utility tests
src/vertex/core/utils/clientCache.test.ts, src/vertex/core/utils/rememberedAccounts.test.ts, src/vertex/core/utils/sessionManager.test.ts, src/vertex/core/utils/userPreferences.test.ts
Adds tests for localStorage/sessionStorage behavior in clientCache, rememberedAccounts, sessionManager, and userPreferences.
Pure utility tests
src/vertex/core/utils/cohortName.test.ts, src/vertex/core/utils/getApiErrorMessage.test.ts, src/vertex/core/utils/status.test.ts, src/vertex/core/utils/urlHelpers.test.ts
Adds tests for cohortName, getApiErrorMessage, status, and urlHelpers helper behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

ready for review, vertex

Suggested reviewers

  • OchiengPaul442
  • Baalmart

Poem

Vitest arrived with quiet light,
and tests began to hold the night.
Storage now remembers true,
while CI checks the code anew.
A small green spark across the stack,
and docs guide every step back.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Issue #3605 is satisfied, but #3626 is not: the workflow adds type-check and npm run test:coverage steps instead of the required Test step running cd src/vertex && npm run test after Lint. Add the required Test step immediately after Lint in check-vertex, running cd src/vertex && npm run test, and avoid replacing it with coverage-only or extra workflow changes.
Out of Scope Changes check ⚠️ Warning The PR adds substantial work beyond the linked issues, including utility test suites, README/docs updates, and removing responsive.ts. Split the extra tests, docs, and utility deletion into separate PRs or add matching issues before merging this one.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main change: setting up Vitest testing infrastructure and tests for the Vertex app.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch unit-testing-setup

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

New azure vertex changes available for preview here

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/vertex/core/utils/clientCache.test.ts (1)

6-9: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid pinning the cache version string in the test.

CLIENT_CACHE_VERSION is a release knob, so every intentional version bump will break this suite even if runClientCacheMaintenance() still behaves correctly. Prefer deriving the current version from the module behavior or importing the constant if you want an exact-value assertion here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/vertex/core/utils/clientCache.test.ts` around lines 6 - 9, The test is
hard-coding the client cache version string, which makes it brittle whenever the
cache version is intentionally bumped. Update the assertions in
clientCache.test.ts to use the source of truth for the version, either by
importing CLIENT_CACHE_VERSION or by deriving the expected value from the module
behavior around runClientCacheMaintenance(). Keep the rest of the key checks
(VERSION_KEY, QUERY_CACHE_PREFIX, MISMATCH_LOG_KEY) intact and avoid pinning an
exact release-specific literal in the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/safe-checks.yml:
- Around line 101-104: Update the safe-checks workflow job to use Node 20.19+
instead of Node 18 so the new Type Check and Test & Coverage steps run on a
supported runtime. Locate the job that uses actions/setup-node in the workflow
and bump the configured Node version to 20.19.0 or newer, keeping the rest of
the job steps unchanged.

---

Nitpick comments:
In `@src/vertex/core/utils/clientCache.test.ts`:
- Around line 6-9: The test is hard-coding the client cache version string,
which makes it brittle whenever the cache version is intentionally bumped.
Update the assertions in clientCache.test.ts to use the source of truth for the
version, either by importing CLIENT_CACHE_VERSION or by deriving the expected
value from the module behavior around runClientCacheMaintenance(). Keep the rest
of the key checks (VERSION_KEY, QUERY_CACHE_PREFIX, MISMATCH_LOG_KEY) intact and
avoid pinning an exact release-specific literal in the test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 26b288fb-68b6-49f7-bf53-c21e59310e95

📥 Commits

Reviewing files that changed from the base of the PR and between cd214aa and 8baa34d.

⛔ Files ignored due to path filters (1)
  • src/vertex/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (16)
  • .github/workflows/safe-checks.yml
  • src/vertex/README.md
  • src/vertex/app/_docs/internal/TESTING.md
  • src/vertex/core/utils/clientCache.test.ts
  • src/vertex/core/utils/cohortName.test.ts
  • src/vertex/core/utils/getApiErrorMessage.test.ts
  • src/vertex/core/utils/rememberedAccounts.test.ts
  • src/vertex/core/utils/responsive.ts
  • src/vertex/core/utils/sessionManager.test.ts
  • src/vertex/core/utils/status.test.ts
  • src/vertex/core/utils/urlHelpers.test.ts
  • src/vertex/core/utils/userPreferences.test.ts
  • src/vertex/package.json
  • src/vertex/tsconfig.json
  • src/vertex/vitest.config.ts
  • src/vertex/vitest.setup.ts
💤 Files with no reviewable changes (1)
  • src/vertex/core/utils/responsive.ts

Comment thread .github/workflows/safe-checks.yml
@github-actions

Copy link
Copy Markdown
Contributor

New azure vertex changes available for preview here

Update clientCache tests to consistently reference window.localStorage and to use explicit fakeLocalStorage objects for failure scenarios. Replace spyOn-based mutations with temporary Object.defineProperty swaps that simulate getItem/setItem/removeItem failures, then restore the original storage. Also update assertions to read from window.localStorage and ensure tests remain resilient to storage errors.
@github-actions

Copy link
Copy Markdown
Contributor

New azure vertex changes available for preview here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants